package com.dofile;

import org.apache.poi.xwpf.usermodel.*;

import java.io.FileInputStream;
import java.util.List;

/**
 * @author :Mr.zhou
 * @description: TODO edit class Description
 * @create date: 2024/1/4 21:31
 */
public class DocParse {
    public static void main(String[] args) {
        String filePath = "jdemo/src/main/java/com/dofile/解析用例1.docx";
        try {
            FileInputStream fis = new FileInputStream(filePath);
            XWPFDocument doc = new XWPFDocument(fis);
            List<XWPFParagraph> paragraphs = doc.getParagraphs();
            for (XWPFParagraph para : paragraphs) {
                String text = para.getText();
                System.out.println("段落内容：" + text);
                List<XWPFRun> runs = para.getRuns();
                if (text.contains("2023")) {
                    for (XWPFRun run : runs) {
                        System.out.println(run.getText(0)+" : "+run.isStrikeThrough());
                        /*if (run.getStrike() != null && run.getStrike().equals(Strike.THROUGH)) {
                            String text = run.getText(0);
                        }*/
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
